<% if section.blocks.any? %>
  <% section.blocks.includes(:links).each do |block| %>
    <% presenter = Spree::MegaNavPresenter.new(block) %>
    <% main_link = presenter.main_link %>
    <% next unless main_link.present? %>
    <div class="header--nav-item group" <%= block_attributes(block, allowed_styles: ['padding-top', 'padding-bottom']) %>>
      <%= active_link_to spree_storefront_resource_url(main_link.linkable || main_link),
          active: main_link.linkable.present? && main_link.linkable.is_a?(Spree::Pages::Homepage) ? :exclusive : :inclusive,
          data: { title: main_link.label.downcase.strip },
          class: "shrink-0 menu-item header--nav-link px-4 py-1",
          class_active: "menu-item--active",
          target: main_link.open_in_new_tab.presence && "_blank",
          rel: main_link.open_in_new_tab.presence && "noopener noreferrer" do %>
        <span class="group-hover:border-b-[1.5px] group-hover:border-b-accent"><%= main_link.label %></span>
      <% end %>
      <% if presenter.columns.any? %>
        <div class="w-full bg-transparent invisible absolute translate-y-[10%] group-hover:translate-y-0 left-0 group-hover:opacity-100 opacity-0 group-hover:visible transition-none border-default border-b duration-150 ease-in block pointer-events-none group-hover:pointer-events-auto z-10 header--mega-nav-container" style="--bottom-padding: <%= section.preferred_bottom_padding %>px; --top-without-bottom-padding: calc(100% - var(--bottom-padding)); padding-top: calc(var(--bottom-padding) + var(--section--border-bottom-width)); top: var(--top-without-bottom-padding);">
          <div class="bg-section-background">
            <div class="page-container py-6 grid grid-cols-4 gap-5">
              <% presenter.columns.each do |column| %>
                <div class="flex flex-col">
                  <h6 class="uppercase text-sm tracking-widest px-2 font-semibold mb-5"><%= column.title %></h6>
                  <% column.links.each do |link| %>
                    <div class="p-2">
                      <%= page_builder_link_to link, data: { title: link.label.downcase.strip }, class: "shrink-0 menu-item !normal-case header--nav-link", target: link.open_in_new_tab.presence && "_blank", rel: link.open_in_new_tab.presence && "noopener noreferrer" do %>
                        <span><%= link.label %></span>
                      <% end %>
                    </div>
                  <% end %>
                  <%= link_to Spree.t(:view_all), spree_storefront_resource_url(column.view_all_linkable), class: "py-3 px-2 uppercase text-sm inline-block tracking-widest font-semibold" %>
                </div>
              <% end %>
              <% if block.try(:featured_taxon) %>
                <% cache spree_storefront_base_cache_scope.call(block.featured_taxon) do %>
                  <% if block.featured_taxon.image.attached? && block.featured_taxon.image.variable? %>
                    <%= link_to spree_storefront_resource_url(block.featured_taxon), class: "flex flex-col col-start-4" do %>
                      <%= spree_image_tag(block.featured_taxon.image, width: 360, height: 360, class: 'w-full h-auto aspect-1', loading: :lazy, alt: block.featured_taxon.name) %>
                      <span class="py-3 px-2 bg-accent block uppercase text-sm tracking-widest font-semibold header--mega-nav-featured-taxon-title"><%= Spree.t(:explore_taxon, taxon_name: block.featured_taxon.name) %></span>
                    <% end %>
                  <% end %>
                <% end %>
              <% end %>
            </div>
          </div>
        </div>
      <% end %>
    </div>
  <% end %>
<% else %>
  <% section.links.each do |link| %>
    <%= active_link_to spree_storefront_resource_url(link.linkable || link),
        active: link.linkable.present? && link.linkable.is_a?(Spree::Pages::Homepage) ? :exclusive : :inclusive,
        data: { title: link.label.downcase.strip },
        class: "shrink-0 menu-item header--nav-link px-4 py-1 focus:mx-0 focus:px-4",
        class_active: "menu-item--active",
        target: link.open_in_new_tab.presence && "_blank",
        rel: link.open_in_new_tab.presence && "noopener noreferrer",
        **link_attributes(link, as_html: false) do %>
      <span><%= link.label %></span>
    <% end %>
  <% end %>
<% end %>
